import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:wanandroid_client/theme/app_colors.dart';

class BottomNavItem {
  final String text;
  final String iconPath;

  const BottomNavItem({required this.text, required this.iconPath});
}

class BottomNavigation extends StatelessWidget {
  final List<BottomNavItem> navItems;
  final Function(int) onTap;
  final int selectedIndex;

  const BottomNavigation({
    super.key,
    required this.navItems,
    required this.onTap,
    required this.selectedIndex,
  });

  List<Widget> _createWidgets() {
    final ws = <Widget>[];
    for (var idx = 0; idx < navItems.length; idx++) {
      final item = navItems[idx];
      final widget =
          [
                Image.asset(
                  item.iconPath,
                  color: idx == selectedIndex ? const Color(0xFFE57815) : null,
                  fit: BoxFit.cover,
                  colorBlendMode: BlendMode.srcIn,
                ).constrained(width: 24.w, height: 24.w).marginOnly(top: 6.h),
                Text(
                  item.text,
                  style: TextStyle(
                    color: idx == selectedIndex
                        ? const Color(0xFFE57815)
                        : Colors.black,
                    fontSize: 14.sp,
                    fontWeight: FontWeight.w500,
                  ),
                ),
              ]
              .toColumnSpace(
                mainAxisSize: MainAxisSize.min,
                crossAxisAlignment: CrossAxisAlignment.center,
                space: 1.h,
              )
              .onTap(behavior: HitTestBehavior.opaque, () {
                onTap(idx);
              })
              .expanded();
      ws.add(widget);
    }
    return ws;
  }

  @override
  Widget build(BuildContext context) {
    return BottomAppBar(
      color: Colors.white,
      elevation: 3,
      shadowColor: AppColors.color000000,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [..._createWidgets()],
      ),
    );
  }
}
